package com.neusoft.movie.v_movies.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.neusoft.movie.v_movies.R;
import com.neusoft.movie.v_movies.activity.AboutUsActivity;
import com.neusoft.movie.v_movies.activity.AddFeedbackActivity;
import com.neusoft.movie.v_movies.activity.BaseActivity;
import com.neusoft.movie.v_movies.activity.ModifyMyInfoActivity;
import com.neusoft.movie.v_movies.activity.ModifyPersonalActivity;
import com.neusoft.movie.v_movies.activity.MyColArtActivity;
import com.neusoft.movie.v_movies.activity.MyColMoviesActivity;
import com.neusoft.movie.v_movies.activity.MyColUsersActivity;
import com.neusoft.movie.v_movies.activity.MyEnteredActActivity;
import com.neusoft.movie.v_movies.activity.MyWriteActivity;
import com.neusoft.movie.v_movies.common.Constants;
import com.neusoft.movie.v_movies.javabean.UsersBean;
import com.neusoft.movie.v_movies.listener.RetrofitListener;
import com.neusoft.movie.v_movies.model.UsersModel;

/**
 * Created by Administrator on 2017/12/25.
 */

public class MeFragment extends BaseFragment implements RetrofitListener {

    private TextView u_name,u_personal,button_enter_activity,
            button_collect_movies,button_collect_users,button_collect_articles;
    private Context mContext;
    private LinearLayout button_update,
            button_logout,
            button_about_us,
            button_add_feedback,
            button_my_articles;

    private int u_id;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,@Nullable Bundle savedInstanceState) {
        setLayout_file(R.layout.mtab05);
        return super.onCreateView(inflater, container, savedInstanceState);
    }
    @Override
    void initViews() {

        SharedPreferences sp=getActivity().getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id = sp.getInt("u_id",0);

        u_name = (TextView)view.findViewById(R.id.u_name);
        u_personal = (TextView) view.findViewById(R.id.u_personal);
        button_enter_activity= (TextView) view.findViewById(R.id.button_enter_activity);
        button_collect_movies= (TextView) view.findViewById(R.id.button_collect_movies);
        button_collect_users= (TextView) view.findViewById(R.id.button_collect_users);
        button_collect_articles= (TextView) view.findViewById(R.id.button_collect_articles);

        button_update= (LinearLayout) view.findViewById(R.id.button_update);
        button_my_articles= (LinearLayout) view.findViewById(R.id.button_my_articles);
        button_add_feedback= (LinearLayout) view.findViewById(R.id.button_add_feedback);
        button_about_us= (LinearLayout) view.findViewById(R.id.button_about_us);
        button_logout= (LinearLayout) view.findViewById(R.id.button_logout);
    }

    @Override
    void initData() {

        getUserInfo();

    }
    void getUserInfo()
    {
        UsersModel usersModel = new UsersModel();
        usersModel.getUserInfo(u_id,this);
    }


    @Override
    void initEvents() {
        u_personal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), ModifyPersonalActivity.class);
                startActivity(intent);
            }
        });

        button_enter_activity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), MyEnteredActActivity.class);
                startActivity(intent);
            }
        });

        button_collect_movies.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), MyColMoviesActivity.class);
                startActivity(intent);
            }
        });


        button_collect_users.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), MyColUsersActivity.class);
                startActivity(intent);
            }
        });

        button_collect_articles.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), MyColArtActivity.class);
                startActivity(intent);
            }
        });


        button_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), ModifyMyInfoActivity.class);
                startActivity(intent);
            }
        });
        button_my_articles.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), MyWriteActivity.class);
                startActivity(intent);

            }
        });
        button_add_feedback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), AddFeedbackActivity.class);
                startActivity(intent);
            }
        });

        button_about_us.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                Intent intent = new Intent();
                intent.setClass(MeFragment.this.getActivity(), AboutUsActivity.class);
                startActivity(intent);
            }
        });

    }

    @Override
    public void onSuccess(Object o, int flag) {
        switch(flag){
            case Constants.GETUSERINFO:
                UsersBean usersBean=(UsersBean) o;
                u_name.setText(usersBean.getU_name());
                u_personal.setText(usersBean.getU_personal());

                break;


        }
    }

    @Override
    public void onFailed() {

    }
}

